﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tomato.Libraries.Databases.Models;

namespace Tomato.Libraries.Databases
{
    /// <summary>
    /// Initializes tables and data.
    /// </summary>
    public class ExpenseDiaryDatabaseInitializer
    {

        private string _path;

        public ExpenseDiaryDatabaseInitializer( string path = "expensediary.db" )
        {
            _path = path;
        }

        /// <summary>
        /// Creates table and fill data.
        /// </summary>
        public void Up( )
        {
            using ( var db = new ExpenseDiaryDatabase( _path ) )
            {

                #region Currency

                db.Purge<Currency>( );

                var currencies = new[ ]
                {
                    new Currency { Code = "ALL", Name = "Albania Lek", Symbol = "Lek", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "AFN", Name = "Afghanistan Afghani", Symbol = "؋", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ARS", Name = "Argentina Peso", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "AWG", Name = "Aruba Guilder", Symbol = "ƒ", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "AUD", Name = "Australia Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "AZN", Name = "Azerbaijan New Manat", Symbol = "ман", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BSD", Name = "Bahamas Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BBD", Name = "Barbados Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BYR", Name = "Belarus Ruble", Symbol = "p.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BZD", Name = "Belize Dollar", Symbol = "BZ$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BMD", Name = "Bermuda Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BOB", Name = "Bolivia Boliviano", Symbol = "$b", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BAM", Name = "Bosnia and Herzegovina Convertible Marka", Symbol = "KM", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BWP", Name = "Botswana Pula", Symbol = "P", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BGN", Name = "Bulgaria Lev", Symbol = "лв", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BRL", Name = "Brazil Real", Symbol = "R$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "BND", Name = "Brunei Darussalam Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KHR", Name = "Cambodia Riel", Symbol = "៛", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CAD", Name = "Canada Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KYD", Name = "Cayman Islands Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CLP", Name = "Chile Peso", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CNY", Name = "China Yuan Renminbi", Symbol = "¥", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "COP", Name = "Colombia Peso", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CRC", Name = "Costa Rica Colon", Symbol = "₡", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "HRK", Name = "Croatia Kuna", Symbol = "kn", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CUP", Name = "Cuba Peso", Symbol = "₱", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CZK", Name = "Czech Republic Koruna", Symbol = "Kč", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "DKK", Name = "Denmark Krone", Symbol = "kr", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "DOP", Name = "Dominican Republic Peso", Symbol = "RD$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "XCD", Name = "East Caribbean Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "EGP", Name = "Egypt Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SVC", Name = "El Salvador Colon", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "EEK", Name = "Estonia Kroon", Symbol = "kr", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "EUR", Name = "Euro Member Countries", Symbol = "€", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "FKP", Name = "Falkland Islands (Malvinas) Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "FJD", Name = "Fiji Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GHC", Name = "Ghana Cedi", Symbol = "¢", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GIP", Name = "Gibraltar Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GTQ", Name = "Guatemala Quetzal", Symbol = "Q", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GGP", Name = "Guernsey Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GYD", Name = "Guyana Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "HNL", Name = "Honduras Lempira", Symbol = "L", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "HKD", Name = "Hong Kong Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "HUF", Name = "Hungary Forint", Symbol = "Ft", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ISK", Name = "Iceland Krona", Symbol = "kr", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "INR", Name = "India Rupee", Symbol = "", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "IDR", Name = "Indonesia Rupiah", Symbol = "Rp", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "IRR", Name = "Iran Rial", Symbol = "﷼", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "IMP", Name = "Isle of Man Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ILS", Name = "Israel Shekel", Symbol = "₪", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "JMD", Name = "Jamaica Dollar", Symbol = "J$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "JPY", Name = "Japan Yen", Symbol = "¥", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "JEP", Name = "Jersey Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KZT", Name = "Kazakhstan Tenge", Symbol = "лв", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KPW", Name = "Korea (North) Won", Symbol = "₩", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KRW", Name = "Korea (South) Won", Symbol = "₩", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "KGS", Name = "Kyrgyzstan Som", Symbol = "лв", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LAK", Name = "Laos Kip", Symbol = "₭", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LVL", Name = "Latvia Lat", Symbol = "Ls", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LBP", Name = "Lebanon Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LRD", Name = "Liberia Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LTL", Name = "Lithuania Litas", Symbol = "Lt", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MKD", Name = "Macedonia Denar", Symbol = "ден", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MYR", Name = "Malaysia Ringgit", Symbol = "RM", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MUR", Name = "Mauritius Rupee", Symbol = "₨", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MXN", Name = "Mexico Peso", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MNT", Name = "Mongolia Tughrik", Symbol = "₮", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "MZN", Name = "Mozambique Metical", Symbol = "MT", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "NAD", Name = "Namibia Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "NPR", Name = "Nepal Rupee", Symbol = "₨", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ANG", Name = "Netherlands Antilles Guilder", Symbol = "ƒ", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "NZD", Name = "New Zealand Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "NIO", Name = "Nicaragua Cordoba", Symbol = "C$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "NGN", Name = "Nigeria Naira", Symbol = "₦", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "OMR", Name = "Oman Rial", Symbol = "﷼", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PKR", Name = "Pakistan Rupee", Symbol = "₨", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PAB", Name = "Panama Balboa", Symbol = "B/.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PYG", Name = "Paraguay Guarani", Symbol = "Gs", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PEN", Name = "Peru Nuevo Sol", Symbol = "S/.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PHP", Name = "Philippines Peso", Symbol = "₱", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "PLN", Name = "Poland Zloty", Symbol = "zł", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "QAR", Name = "Qatar Riyal", Symbol = "﷼", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "RON", Name = "Romania New Leu", Symbol = "lei", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "RUB", Name = "Russia Ruble", Symbol = "руб", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SHP", Name = "Saint Helena Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SAR", Name = "Saudi Arabia Riyal", Symbol = "﷼", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "RSD", Name = "Serbia Dinar", Symbol = "Дин.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SCR", Name = "Seychelles Rupee", Symbol = "₨", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SGD", Name = "Singapore Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SBD", Name = "Solomon Islands Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SOS", Name = "Somalia Shilling", Symbol = "S", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ZAR", Name = "South Africa Rand", Symbol = "R", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "LKR", Name = "Sri Lanka Rupee", Symbol = "₨", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SEK", Name = "Sweden Krona", Symbol = "kr", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "CHF", Name = "Switzerland Franc", Symbol = "CHF", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SRD", Name = "Suriname Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "SYP", Name = "Syria Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "TWD", Name = "Taiwan New Dollar", Symbol = "NT$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "THB", Name = "Thailand Baht", Symbol = "฿", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "TTD", Name = "Trinidad and Tobago Dollar", Symbol = "TT$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "TRY", Name = "Turkey Lira", Symbol = "", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "TRL", Name = "Turkey Lira", Symbol = "₤", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "TVD", Name = "Tuvalu Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "UAH", Name = "Ukraine Hryvnia", Symbol = "₴", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "GBP", Name = "United Kingdom Pound", Symbol = "£", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "USD", Name = "United States Dollar", Symbol = "$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "UYU", Name = "Uruguay Peso", Symbol = "$U", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "UZS", Name = "Uzbekistan Som", Symbol = "лв", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "VEF", Name = "Venezuela Bolivar", Symbol = "Bs", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "VND", Name = "Viet Nam Dong", Symbol = "₫", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "YER", Name = "Yemen Rial", Symbol = "﷼", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new Currency { Code = "ZWD", Name = "Zimbabwe Dollar", Symbol = "Z$", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }
                };

                db.Currencies.Save( currencies );
                #endregion Currency

                #region AccountCategory

                db.Purge<AccountCategory>( );

                var accountCategories = new[ ]
                {
                    new AccountCategory { Name = "Cash", Description = "Cash.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new AccountCategory { Name = "Credit", Description = "Credit card.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now },
                    new AccountCategory { Name = "Others", Description = "Unspecified category.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }
                };

                db.AccountCategories.Save( accountCategories );

                #endregion AccountCategory

                #region TransactionCategoryGroup

                db.Purge<TransactionCategoryGroup>( );

                var transactionCategoryGroups = new[ ]
                {
                    new TransactionCategoryGroup{ Name = "Expense", Description = "Negative transaction category.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }
                    , new TransactionCategoryGroup{ Name = "Income", Description = "Positive transaction category.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }
                    , new TransactionCategoryGroup{ Name = "Exchange", Description = "Transaction of category to transfer money between 2 accounts.", CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now }
                };

                db.TransactionCategoryGroups.Save( transactionCategoryGroups );

                #endregion TransactionCategoryGroup

            }
        }
    }
}
